PRG 1.0 TXT

/*
*/

//-----------------------------------------------------------------------------
// [CONFIG]

include "..\program_include.ocf"

object Program
{
	type		= e_program.PARALLAX;
	layer_bits	= e_render_layer_bits.OPAQUE;
	
	ubo_data	= array /*UBO*/ {
		{ "inMaterial",  e_program_data.MATERIAL }
	}

	textures	= array /*ProgramTexture*/ {
		{ "unDiffuseMap", e_texture.DIFFUSE },
		{ "unNormalMap",  e_texture.NORMAL },
		{ "unHeightMap",  e_texture.HEIGHT }
	}
	
	uniforms	= array /*string*/ {
		"transform", "unTransform."
	}
}


//-----------------------------------------------------------------------------
// [VERTEX]

#version 330 core
#pragma optimize(on)

#define ATTR_POSITION	0
#define ATTR_NORMAL		1
#define ATTR_TEXCOORD	2
#define ATTR_TANGENT	3
#define ATTR_BINORMAL	4

layout(location = ATTR_POSITION)	in vec3  inPosition;
layout(location = ATTR_NORMAL)		in vec3  inNormal;
layout(location = ATTR_TEXCOORD)	in vec2  inTexcoord;
layout(location = ATTR_TANGENT)		in vec3  inTangent;
layout(location = ATTR_BINORMAL)	in vec3  inBinormal;

uniform struct TTransform {
	mat4	MVP;
	mat4	MV;
	mat3	Normal;
} unTransform;


out	TVertexData {
	vec2	vTexcoord;
	vec3	vNormal;
	vec3	vTangent;
	vec3	vBinormal;
	float	fDepth;
} Output;


void main()
{
	gl_Position		 = unTransform.MVP * vec4(inPosition, 1.0);
	Output.fDepth	 = ( unTransform.MV * vec4(inPosition, 1.0) ).z;
	Output.vTexcoord = inTexcoord;
	Output.vNormal	 = inNormal * unTransform.Normal;
	Output.vTangent	 = inTangent * unTransform.Normal;
	Output.vBinormal = inBinormal * unTransform.Normal;
}


//-----------------------------------------------------------------------------
// [FRAGMENT]

#version 330 core
#pragma optimize(on)

layout(location = 0)	out vec4	outDNNS;	// depth, normal(x,y), Shininness
layout(location = 1)	out vec4	outRGBM;	// colorRGB, MaterialID

uniform sampler2D	unDiffuseMap;
uniform sampler2D	unNormalMap;
uniform sampler2D	unHeightMap;

layout(std140)
uniform inMaterial {
	vec3	vAmbientColor;
	vec4	vDiffuseColor;
	vec3	vSpecularColor;
	vec3	vEmissionColor;
	float	fShininess;
} unMaterial;


in	TVertexData {
	vec2	vTexcoord;
	vec3	vNormal;
	vec3	vTangent;
	vec3	vBinormal;
	float	fDepth;
} Input;


vec2 CalcOutputNormal(vec3 vNormal)
{
	vec2	res = ( vNormal.xy + vec2(1.0) ) * 0.5;
	res.x *= ( vNormal.z < 0.0 ? -1.0 : 1.0 );
	return res;
}

void main()
{
	vec4	color = texture( unDiffuseMap, Input.vTexcoord ) * unMaterial.vDiffuseColor;

	// TODO: parallax mapping

	outDNNS.r   = Input.fDepth;
	outDNNS.gb  = CalcOutputNormal( normalize( Input.vNormal ) );
	outDNNS.a	= unMaterial.fShininess;
	outRGBM.rgb	= color.rgb;
	outRGBM.a   = 0.0;
}

// [END]
